package com.guchenghao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guchenghao.entity.Article;
import com.guchenghao.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @User 20675
 * @Author gch
 * @Date 2025/3/26 22:11
 * @Description <br />
 * <p>
 * <br />
 */
@Controller
public class IndexController {
    @Autowired
    private ArticleService articleService;

    // 跳转到 首页 页面
    @GetMapping("/")
    public String toIndex() {
        return "index";
    }

    // 首页文章展示
    @GetMapping("/index/show")
    @ResponseBody
    public Page<Article> showArticles(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", required = false, defaultValue = "9") Integer pageSize) {
        return articleService.showArticles(pageNum, pageSize);
    }
}
